package com.myweb.common;

import java.io.InputStream;
import java.util.Properties;


/**
 * 
 * @TODO 读取配置文件中的属性
 * @author roye
 * @date May 3, 2013 2:27:22 PM
 * @version V1.0
 */
public class ReadConfigFile {

	//系统名称
	public static String SYSNAME="";
	/***
	 * 文件路径必需放在 项目的webapp文件夹下
	 * 
	 * */
	private static Properties prop=null;
	
	static{
		@SuppressWarnings("unused")
		String path="/config/windows.properties";
		if(isLinux()){
			path="/config/linux.properties";
		}
		InputStream in=ReadConfigFile.class.getResourceAsStream(path);
		if(in!=null){
			prop=new Properties();
			try {
				prop.load(in);
				SYSNAME=(String) prop.get("SYSNAME");
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
	}
	
	public static String getPropValue(String key){
		String path="/config/windows.properties";
		String val = null;
		if(isLinux()){
			path="/config/linux.properties";
		}
		InputStream in=ReadConfigFile.class.getResourceAsStream(path);
		if(in!=null){
			prop=new Properties();
			try {
				prop.load(in);
				val = prop.getProperty(key);
			} catch (Exception e) {
				e.printStackTrace();	
			}
		}
		return val;
	}
	
	public  static boolean isLinux(){
		String osType = System.getProperties().getProperty("os.name").toLowerCase();
		String xmlPath="";
		if(osType.startsWith("windows")){
			return false;
		}
		else{
			return true;
		}
	}
}
